import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/res/colors.dart';
import 'package:ls_work/ui/service_order/service_order_list_home_page.dart';
import 'package:ls_work/ui/service_order/service_order_statistics_page.dart';
import 'package:ls_work/viewmodel/service_order/service_order_home_view_model.dart';
import 'package:ls_work/widgets/customer_under_line_tab_indicator.dart';

import 'add_service_order_page.dart';
import 'my_service_order_home_page.dart';

class ServiceOrderHomePage extends BaseStatefulMvvmWidget {
  @override
  State<StatefulWidget> createState() => _ServiceOrderHomeState();
}

class _ServiceOrderHomeState
    extends BaseMvvmState<ServiceOrderHomeViewModel, ServiceOrderHomePage>
    with SingleTickerProviderStateMixin {
  TabController? controller;

  List<String> get titles => ["服务单统计", "服务单处理","我的提交"];

  @override
  void initState() {
    super.initState();
    controller = TabController(length: titles.length, vsync: this);
  }

  @override
  Widget buildLoadingContentView() {
    return Column(
      children: [
        TabBar(
          tabs: titles
              .map((e) => Tab(
                    text: e,
                  ))
              .toList(),
          controller: controller,
          unselectedLabelColor: Colors.black,
          labelColor: Colors.black,
          indicator: CustomUnderlineTabIndicator(borderRadius: 6.borderRadius,width: 32,
          borderSide: BorderSide(color: Colours.app_main,width: 4)),
          indicatorPadding: EdgeInsets.only(bottom: 10),
          // indicatorColor: Colours.app_main,
          // indicatorSize: TabBarIndicatorSize.label ,
          labelStyle: TextStyle(fontWeight: FontWeight.bold, fontSize: 15),
          unselectedLabelStyle:
              TextStyle(fontWeight: FontWeight.normal, fontSize: 14),
        ).addToContainer(color: Colors.white),
        TabBarView(
          children: [
            ServiceOrderStatisticsPage(),
            ServiceOrderListHomePage(),
            MyServiceOrderHomePage()
          ],
          controller: controller,
        ).setWeight(1)
      ],
    );
  }

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      backgroundColor: Colours.bg_color,
      appBar: AppBar(
        title: Text('服务响应'),
        actions: [
          CommonText('新增服务单',
                  textColor: Colours.app_main, fontWeight: FontWeight.bold)
          .onTap(() {
            Go().push(AddServiceOrderPage());
          })
              .addToContainer(
                  alignment: Alignment.center,
                  margin: EdgeInsets.only(right: 16)),
        ],
      ),
      body: loadingContentWidget,
    );
  }

  @override
  ServiceOrderHomeViewModel createViewModel() {
    return ServiceOrderHomeViewModel(context);
  }

  @override
  void onRetryClick() {
    // TODO: implement onRetryClick
  }
}
